var htmlWP = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack');
var path = require('path');
module.exports = {
    // entry: './src/main.js', //指定打包的入口文件
    entry: {
        app: path.resolve(__dirname, 'src/main.js'),
        // 需要分离的第三方包名写在数组中
        vendors: ['vue', 'vue-resource', 'vue-router', 'vuex', 'mint-ui', 'moment', 'vue-preview']
    },
    output: {
        path: __dirname + '/dist',
        filename: 'build.js'
    },

    module: {
        loaders: [{
                test: /\.css$/,
                // loader: 'style!css',
                loader: ExtractTextPlugin.extract("style-loader", "css-loader")
            },
            {
                test: /\.scss$/,
                loader: 'style!css!sass'
            },
            {
                test: /\.less$/,
                loader: 'style!css!less'
            },
            {
                test: /\.(jpg|png|gif|ttf|svg)$/,
                loader: 'url?limit=5000'
            },
            {
                test: /\.js$/,
                loader: 'babel',
                exclude: /node_modules/
            },
            {
                test: /\.vue$/,
                loader: 'vue',
            },
            {
                test: /vue-preview.src.*?js$/, // vue-preivew组件专用
                loader: 'babel-loader'
            }
        ]
    },
    babel: {
        presets: ['es2015'],
        plugins: ['transform-runtime']
    },
    plugins: [
        new htmlWP({
            title: '首页', //生成的页面标题
            filename: 'index.html', //webpack-dev-server在内存中生成的文件名称，自动将build注入到这个页面底部，才能实现自动刷新功能
            template: 'template.html', //template.html这个模板来生成(这个文件请程序员自己生成)
            // 代码压缩
            minify: {
                // 删除注释
                removeComments: true,
                // 删除空格
                collapseWhitespace: true,
                // 删除空格缩进
                removeAttributeQuotes: true
            }
        }),
        new webpack.optimize.UglifyJsPlugin({
            beautify: false,
            mangle: {
                screw_ie8: true,
                keep_fnames: true
            },
            compress: {
                warnings: false,
                screw_ie8: true
            },
            comments: false
        }),
        new webpack.DefinePlugin({
            'process.env': {
                // 注意字符串被引号引起来
                NODE_ENV: '"production"'
            }
        }),
        new ExtractTextPlugin('app.css'),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendors',
            filename: 'vendors.js'
        })
    ]
}

